package com.joolun.web.controller.tool;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

public class SendSmsUtil {
    public static SendSmsResponse send(String mobile, String smsCode, String AccessKeyId, String accessKeySecret) throws Exception {
        // 初始化请求客户端
        Client client = SendSmsUtil.createClient(AccessKeyId,accessKeySecret);

        // 构造请求对象，请填入请求参数值
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName("远航星科技")
                .setTemplateCode("SMS_472465458")
                .setTemplateParam("{\"code\":\""+smsCode+"\"}");
        // 获取响应对象
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        return sendSmsResponse;
    }

    public static Client createClient(String AccessKeyId,String accessKeySecret) throws Exception {
        Config config = new Config().setAccessKeyId(AccessKeyId).setAccessKeySecret(accessKeySecret);
        // 配置 Endpoint
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }
}
